
package com.orhonit.ipb.portal.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.orhonit.ipb.security.auth.client.interceptor.ServiceAuthRestInterceptor;
import com.orhonit.ipb.security.auth.client.interceptor.UserAuthRestInterceptor;
import com.orhonit.ipb.security.common.handler.GlobalExceptionHandler;

@Configuration("duesWebConfig")
@Primary
public class WebConfiguration extends WebMvcConfigurerAdapter {
	@Bean
	GlobalExceptionHandler getGlobalExceptionHandler() {
		return new GlobalExceptionHandler();
	}

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		/*
		 * 增加服务权限烂机器
		 */
		registry.addInterceptor(getServiceAuthRestInterceptor()).addPathPatterns("/**");
		/*
		 * 增加用户权限拦截器
		 */
		registry.addInterceptor(getUserAuthRestInterceptor()).addPathPatterns("/**");
		super.addInterceptors(registry);
	}

	/**
	 * 配置服务权限拦截
	 * 
	 * @return
	 */
	@Bean
	ServiceAuthRestInterceptor getServiceAuthRestInterceptor() {
		return new ServiceAuthRestInterceptor();
	}

	/**
	 * 配置用户用户token拦截
	 * 
	 * @return
	 */
	@Bean
	UserAuthRestInterceptor getUserAuthRestInterceptor() {
		return new UserAuthRestInterceptor();
	}
}
